<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="geometry" content="area">
  <link rel="stylesheet" href="./assets/common.css">
  <title>Guide.Line</title>
</head>

<body>
  <div id="canvas"></div>
  <script src="./assets/jquery-3.2.1.min.js"></script>
  <script src="../build/g2.js"></script>
  <script>
  const data = [
    { year: '1991', value: 3 },
    { year: '1992', value: 4 },
    { year: '1993', value: 3.5 },
    { year: '1994', value: 5 },
    { year: '1995', value: 4.9 },
    { year: '1996', value: 6 },
    { year: '1997', value: 7 },
    { year: '1998', value: 9 },
    { year: '1999', value: 13 }
  ];
  const chart = new G2.Chart({
    container: 'canvas',
    forceFit: true,
    height: window.innerHeight
  });
  chart.source(data);
  chart.scale('value', {
    min: 0
  });
  chart.tooltip({
    crosshairs: {
      type: 'line'
    }
  });
  // 绘制 Guide.Line
  chart.guide().line({
    start: [ '0%', 8 ],
    end: [ '100%', 8 ],
    text: {
      content: 'Y 轴预警线'
    }
  });
  chart.interval().position('year*value').style({
    lineWidth: 1,
    stroke: '#fff'
  });
  chart.render();
  </script>
</body>

</html>
